{% extends "search/base.html" %}
{% from 'includes/common_macros.html' import for_contributors_sidebar %}
{% from "search/includes/result.html" import search_result with context %}
{% from "search/includes/macros.html" import basic_search_form with context %}
{% set meta = (('WT.oss', q), ('WT.oss_r', num_results), ('robots', 'noindex')) %}

{% if advanced %}
  {% set title = _('Advanced Search Results') %}
  {% set crumbs = [(url('search.advanced'), _('Advanced Search')), (None, _('Results'))] %}
{% endif %}

{% block content %}
  <div id="search-results">
    {% if not advanced %}
      <div class="grid_12">
        {{ basic_search_form(True) }}
      </div>
    {% endif %}
    <div class="grid_3">
      {% if not advanced %}
        {# Don't show filtering to advanced search users #}
        {% set base_url = url('search')|urlparams(q=q) %}
        {% set base_product_url = base_url %}
        {% if w != 3 %}
          {% set base_product_url = base_product_url|urlparams(w=w) %}
        {% endif %}
        <ul id="product-filter" class="search-filter sidebar-nav">
          <li {{ product|class_selected(None) }}>
            <a href="{{ base_product_url|urlparams(all_products=1) }}">
              {{ _('All Products') }}
            </a>
          </li>
          {% for p in products %}
            <li {{ product|class_selected(p) }}>
              <a href="{{ base_product_url|urlparams(product=p.slug) }}">
                {{ pgettext('DB: products.Product.title', p.title) }}
              </a>
            </li>
          {% endfor %}
        </ul>
      {% endif %}
      {{ for_contributors_sidebar(user, settings.WIKI_DEFAULT_LANGUAGE) }}
      <br />
    </div>

    <div class="grid_9">
      {% if num_results > 0 %}
        <h2>
          {# L10n: {n} is the number of search results, {q} is the search query, {product} is the product. #}
          {{ ngettext('Found <strong>{n}</strong> result for <strong>{q}</strong> for <strong>{product}</strong>',
                      'Found <strong>{n}</strong> results for <strong>{q}</strong> for <strong>{product}</strong>',
                      num_results)|fe(n=num_results, q=q, product=product_titles) }}
        </h2>

        <div class="content-box">
          {% for doc in results %}
            {{ search_result(doc) }}
          {% endfor %}
        </div>

        {{ pages|paginator }}
      {% else %}
        <h2>
          {# L10n: {q} is the search query, {l} is the language searched. #}
          {{ _("We couldn't find any results for <strong>{q}</strong> in <strong>{l}</strong>. Maybe one of these articles will be helpful?")|fe(q=q, l=lang_name) }}
        </h2>

        <div class="content-box">
          {% for doc in fallback_results %}
            <div class="result document">
              <h3><a class="title" href="{{ doc.url }}">{{ doc.document_title }}</a></h3>
              <a tabindex="-1" href="{{ doc.url }}">{{ doc.document_summary }}</a>
            </div>
          {% endfor %}
        </div>
      {% endif %}
    </div>
    <div class="clear-floats">
      {% if num_results > 3 or num_results == 0 %}
        {{ basic_search_form() }}
      {% endif %}
    </div>
  </div>
{% endblock %}
